﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace ActivityLibrary1
{
   public  class ConnectDB
    {
        public static SqlConnection Getconnect()
        {
            string str = ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
            SqlConnection cn = new SqlConnection(str);
            return cn;
        }
        public static DataTable ExecuteStoredProcedureSelect(string procName, params SqlParameter[] paramList)
        {
            try
            {
                using (SqlConnection con = Getconnect())
                {
                    DataTable dt = new DataTable();
                    SqlCommand cmd = new SqlCommand(procName, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddRange(paramList);
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(dt);
                    return dt;
                }
            }
            catch (Exception)
            {
                //log error here
                return null;
            }
        }

    }
}
